﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data.SqlClient;
using System.Security.Cryptography;

namespace WebLayer
{
    public partial class UserLogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FormsAuthentication.SignOut();
            Response.Redirect("./");
        }

        //Balder.ucn.dk
        string dbConnectionString = "Data Source=balder.ucn.dk;Initial Catalog=dmaa0913_5;User ID=dmaa0913_5;Password=MaaGodt";
        //Local Database
       //stirng dbConnectionString = ""

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (ValidateUser(txtUserName.Text, txtPassword.Text))
                FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);
            //else
            //    lblMsg.Text = "Incorect";
        }

        bool ValidateUser(string user, string pass)
        {
            SqlConnection conn = new SqlConnection(dbConnectionString);

            conn.Open();
            string sql = "select email from customer where email = @email and pass = @pass";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.AddWithValue("@email", user);
            cmd.Parameters.AddWithValue("@pass",pass);
            return cmd.ExecuteScalar() is string;
        }

       
    }
}